package com.gdut.simple.model.impl;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.gdut.simple.basic.BasicApplication;
import com.gdut.simple.common.PhotoUtils;
import com.gdut.simple.common.RequestCallback;
import com.gdut.simple.data.entity.PhotoFolder;
import com.gdut.simple.model.IPhotoPickModel;

import java.util.List;

public class PhotoPickModelImpl implements IPhotoPickModel {

    @Override
    public void getPhotoes(final Context context, final RequestCallback<List<PhotoFolder>> callback) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                final List<PhotoFolder> list = PhotoUtils.getPhotoes(context);
                if (list != null) {
                    if (callback != null) {
                        new Handler(Looper.getMainLooper()).post(new Runnable() {
                            @Override
                            public void run() {
                                callback.onSuccess(list);
                            }
                        });
                    }
                } else {
                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        @Override
                        public void run() {
                            callback.onFailure("unknown error");
                        }
                    });
                }
            }
        }).start();
    }
}
